package tt.dz.egobus.servicemanager.webinit;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.orm.hibernate5.support.OpenSessionInViewFilter;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
import tt.dz.egobus.base.config.ContextConfing;
import tt.dz.egobus.servicemanager.base.config.MVCConfig;

import javax.servlet.Filter;

/**
 * Created by anson-worker on 17-2-28.
 */
public class BaseBootInitializer extends AbstractAnnotationConfigDispatcherServletInitializer implements WebApplicationInitializer {
    protected Logger log = LoggerFactory.getLogger(getClass());

    {
        logger.info(getClass().getName() + " 的对象初始化 .....");
    }

    @Override
    protected Class<?>[] getRootConfigClasses() {
        return new Class<?>[]{ContextConfing.class};
    }

    @Override
    protected String getServletName() {
        return "spring_mvc";
    }

    @Override
    protected Class<?>[] getServletConfigClasses() {
        return new Class<?>[]{MVCConfig.class};
    }

    @Override
    protected String[] getServletMappings() {
        return new String[] { "/*" };
    }

    @Override
    protected Filter[] getServletFilters() {
        OpenSessionInViewFilter osiv = new OpenSessionInViewFilter();
        CharacterEncodingFilter ce = new CharacterEncodingFilter();
        ce.setEncoding("utf-8");
        ce.setForceEncoding(true);
        return new Filter[]{osiv, ce};
    }
}